import React, { Component } from "react";

export default class Child2 extends Component {
  constructor(props) {
    super(props);
    this.state = {
      username: "",
      userage: "",
    };
  }
  render() {
    return (
      <div>
        <div>
          用户名{" "}
          <input
            value={this.state.username}
            onChange={(e) => {
              this.setState({
                username: e.target.value,
              });
            }}
          />
        </div>
        <div>
          年龄 <input  value={this.state.userage} onChange={(e)=>{
            this.setState({
                userage:e.target.value
            })
          }}/>
        </div>
        <button onClick={()=>{
           // alert(this.state.username+"年龄"+this.state.userage)
           this.props.onAdd({
            username:this.state.username,
            userage:this.state.userage
           })
        }}>新增</button>
      </div>
    );
  }
}
